/*
 * Create by erik on 18-8-22 上午10:27
 * Copyright (c) 2018. All rights reserved.
 *
 * Last Modified 18-8-22 上午10:27
 */

package com.feeyo.groundservice.jg

import android.content.Context
import cn.jpush.android.api.CustomMessage
import cn.jpush.android.api.NotificationMessage
import cn.jpush.android.service.JPushMessageReceiver
import com.feeyo.groundservice.fpush.PushBroadCast

class JgReceiver : JPushMessageReceiver() {

    private val TAG = javaClass.simpleName
    override fun onRegister(p0: Context?, p1: String?) {
        super.onRegister(p0, p1)
        println("onRegister:$p1")
        p0?.let {
            PushBroadCast.sendRegistration(it, p1, "jiguang")
        }
    }

    override fun onMessage(p0: Context?, p1: CustomMessage?) {
        super.onMessage(p0, p1)
        p0?.let {
            println("onMessage:$p1")
            PushBroadCast.sendMsgBroadCast(it, p1?.title, p1?.message, p1?.extra)
        }
    }

    override fun onNotifyMessageOpened(p0: Context?, p1: NotificationMessage?) {
        super.onNotifyMessageOpened(p0, p1)
        p0?.let {
            println("onNotifyMessageOpened:$p1")
            PushBroadCast.sendNotificationClick(it, p1?.notificationExtras)
        }
    }

    override fun onNotifyMessageArrived(p0: Context?, p1: NotificationMessage?) {
        super.onNotifyMessageArrived(p0, p1)
        println("onNotifyMessageArrived:$p1")
        p0?.let {
            PushBroadCast.sendNotificationArrived(it, p1?.notificationExtras)
        }
    }
}